package cool.taomu.box.jsch.test

import com.google.inject.Guice
import cool.taomu.box.guice.TaomuGuiceModule
import cool.taomu.box.guice.ann.Binder
import cool.taomu.box.inter.IDataSource
import cool.taomu.box.jsch.Ssh
import java.util.Hashtable
import javax.inject.Inject
import org.junit.Test
import cool.taomu.box.jsch.AbsJschProvider

@Binder(bind=String, named="jsch.host", value="192.168.1.226")
@Binder(bind=String, named="jsch.port", value="22")
@Binder(bind=String, named="jsch.username", value="rcmu")
@Binder(bind=String, named="jsch.passwd", value="mrc2018")
@Binder(bind=IDataSource, to=AProvider, provider=true)
class AProvider extends AbsJschProvider {

	override configure(Hashtable<String, String> sshconfig) {
	}
}

class JschTest {

	@Inject
	Ssh ssh;

	@Test
	def void a() {
		var t = Guice.createInjector(new TaomuGuiceModule().build(AProvider))
		var ssh = t.getInstance(JschTest).ssh
		var res = ssh.exec("ls -l", "UTF-8");
		println(res)
		ssh.close
		ssh = t.getInstance(JschTest).ssh
		res = ssh.exec("ls -l", "UTF-8");
		println(res)
		ssh.close
	}

}
